package com.zbf1811a.service;

import com.alibaba.fastjson.JSON;
import com.zbf1811a.dao.MsgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/7/27  18:04
 * 描述:
 */
@Component
public class UpdateRedisAndMysqlService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private SendMessageService sendMessageService;


    @Autowired
    private MsgMapper msgMapper;

    /**
     * 作者: LCG
     * 日期: 2021/7/27  18:05
     * 描述: 更新redis缓存的菜单信息
     * @Param []
     * @Return void
     */
    public void updateCacheData(){

        //1、删除redis中缓存的数据
        redisTemplate.delete("UUUUU");
        //2、更新数据库的数据

        //3、插入消息表消息
        Map<String,Object> map1111=new HashMap<>();
        String id=UUID.randomUUID().toString().replace("-","");
        map1111.put("id",id);
        map1111.put("status",0);

        Map<String,Object> msg=new HashMap<>();
        msg.put("id",id);
        msg.put("key","UUUUU");

        map1111.put("msg",JSON.toJSONString(msg));

        msgMapper.insert(map1111);

        //4、发送MQ消息
        sendMessageService.sendMesage(JSON.toJSONString(msg),"REDIS-EXCHANGE","REDIS-KEY",id);
    }
}
